#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置快捷键
    QShortcut* shortCut1=new QShortcut(this);
    QShortcut* shortCut2=new QShortcut(this);
    shortCut1->setKey(QKeySequence("-"));
    shortCut2->setKey(QKeySequence("="));//+和=是同一个键位

    connect(shortCut1,&QShortcut::activated,this,[this]()
    {
        int value=ui->horizontalSlider->value();
        if(value<=ui->horizontalSlider->minimum()) return;
        else ui->horizontalSlider->setValue(value-5);
    });

    connect(shortCut2,&QShortcut::activated,this,[this]()
    {
        int value=ui->horizontalSlider->value();
        if(value>=ui->horizontalSlider->maximum()) return;
        else ui->horizontalSlider->setValue(value+5);
    });
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText("当前值为"+QString::number(value));
}
